﻿using System;
using Autodesk.Revit.DB;

namespace YJKWallDesignation
{
	public class WallTypeInfo
	{
		public string WallTypeName
		{
			get
			{
				string result;
				try
				{
					result = this.m_Type.Name;
				}
				catch (Exception)
				{
					result = "";
				}
				return result;
			}
		}

		public bool IsChanged
		{
			get
			{
				return this.m_IsChanged;
			}
		}

		public WallKind TheWallKind
		{
			get
			{
				WallKind result;
				try
				{
					result = this.m_Type.Kind;
				}
				catch (Exception)
				{
                    result = WallKind.Unknown;
				}
				return result;
			}
		}

		public ElementId WallTypeId
		{
			get
			{
				ElementId result;
				try
				{
					result = this.m_Type.Id;
				}
				catch (Exception)
				{
					result = ElementId.InvalidElementId;
				}
				return result;
			}
		}

		public CompoundStructure ComStructure
		{
			get
			{
				CompoundStructure result;
				try
				{
					result = this.m_Type.GetCompoundStructure();
				}
				catch (Exception)
				{
					result = null;
				}
				return result;
			}
			set
			{
				this.m_Type.SetCompoundStructure(value);
			}
		}

		public string FillName
		{
			get
			{
				return this.m_FillName;
			}
			set
			{
				this.m_FillName = value;
			}
		}

		public int ElementsCount
		{
			get
			{
				return this.m_ElementsCount;
			}
			set
			{
				this.m_ElementsCount = value;
			}
		}

		public WallType Duplicate(string newName)
		{
			WallType result;
			try
			{
				result = (this.m_Type.Duplicate(newName) as WallType);
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}

		public void SetWallType(ref Wall wall)
		{
			wall.WallType = this.m_Type;
		}

		public void SetWallTypeName(string newName)
		{
			this.m_Type.Name = newName;
			this.m_IsChanged = true;
		}

		public void DeleteWallType(Autodesk.Revit.DB.Document doc)
		{
			if (!this.IsChanged)
			{
				try
				{
					doc.Delete(this.WallTypeId);
					this.m_Type = null;
					return;
				}
				catch (Exception)
				{
					this.m_Type = null;
					return;
				}
			}
			if (this.IsChanged)
			{
				this.m_IsChanged = false;
			}
		}

		public WallTypeInfo(WallTypeInfo other)
		{
			this.m_Type = other.m_Type;
			this.m_FillName = other.m_FillName;
			this.m_ElementsCount = other.m_ElementsCount;
		}

		public WallTypeInfo(WallType type, string fillName, int elementsCount)
		{
			this.m_Type = type;
			this.m_FillName = fillName;
			this.m_ElementsCount = elementsCount;
		}

		private WallType m_Type;

		private string m_FillName;

		private int m_ElementsCount;

		private bool m_IsChanged;
	}
}
